package _case

import "fmt"

//写法报错 T *int 会识别 乘法运算，所有需要interface包裹起来
//type MyStruct[T *int | *string] struct {
//
//}

// 泛型结构体
type MyStructs[T interface{ *int | *string }] struct {
	Name string
	Data T
}

// 泛型receiver
func (m MyStructs[T]) GetData() T {
	return m.Data
}

func (m MyStructs[T]) GetDatas(t T) T {
	var n interface{} = 1
	i, ok := (n).(int)
	//i, ok := t.(int) //泛型不支持断言
	fmt.Println(i, ok)

	return m.Data
}

func ReceiverCase() {
	data := 18
	myStruct1 := MyStructs[*int]{"jc", &data}
	fmt.Println(*myStruct1.GetData())

	str := "hello"
	myStruct2 := MyStructs[*string]{"jc", &str}
	fmt.Println(*myStruct2.GetData())
}
